import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
import java.text.SimpleDateFormat
import scala.io.Source
import java.io._

object GitPostGenerator {
	
  	//根据title生成blog
  	def gen(title: String){
		val now = new Date
		val fileName = DateFormator.format(now) + "-" + title + ".textile"
		val content = Source.fromFile("template.textile").getLines
		val writer = new PrintWriter(new File(fileName))
		var all = ""
		for(line <- content) {
			all += line.toString + "\n"
		}		
		print(all)  
		writer.write(all)
	  	writer.close()
	}
}

object DateFormator {
	
  	//格式化日期
  	def format(date: Date): String = {
		val df = new SimpleDateFormat("yyyy-MM-dd")
		return df format date
	}
}

if (args.length > 0) {
	val title = args(0)
	GitPostGenerator.gen(title)
}
